﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;


namespace A_larm_Shake
{
    public partial class page_setTimer : PhoneApplicationPage
    {
        public page_setTimer()
        {
            InitializeComponent();
            this.tbx.Text = "";
        }

        private void bt_confirm_Click(object sender, EventArgs e)
        {
            string strName;
            strName = this.tbx.Text;

            string lv = ((ListPickerItem)drop.SelectedItem).Tag.ToString();

            string timess = set_timeSpan.Value.ToString();
           
            // //NavigationService.Navigate(new Uri(("/page_timer.xaml?pName=" + strName + "&tSpan=" + set_timeSpan.Value + "&sLevel=" + lv), UriKind.Relative));

           //// string param1Value = param1TextBox.Text;
           //// string param2Value = param2TextBox.Text;
           // string queryString = "";

           // if (lv != "")
           // {
           //     queryString = "?param1=" + strName + "&param2=" + set_timeSpan.Value + "&param3=" + lv;
           // }
           
           // Uri navigationUri = new Uri("/page_timer.xaml" + queryString, UriKind.Relative);
           // this.NavigationService.GoBack();

           // //NavigationService.Navigate(navigationUri);

            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
            // txtInput is a TextBox defined in XAML.
            if (!settings.Contains("TimerData1"))
            {
                settings.Add("TimerData1", timess);
                settings.Add("TimerData2", lv);
                settings.Add("TimerData3", strName);
            }
            else
            {
                settings["TimerData1"] = timess;
                settings["TimerData2"] = lv;
                settings["TimerData3"] = strName;
            }
            settings.Save();
            this.NavigationService.GoBack();
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();            
            //NavigationService.Navigate(new Uri(("/page_timer.xaml"), UriKind.Relative));
            if (IsolatedStorageSettings.ApplicationSettings.Contains("AlarmData1"))
            {
                IsolatedStorageSettings.ApplicationSettings.Remove("AlarmData1");
                IsolatedStorageSettings.ApplicationSettings.Remove("AlarmData2");
                IsolatedStorageSettings.ApplicationSettings.Remove("AlarmData3");
            }
        }
    }
}